import 'package:example/router/example_routes.dart';
import 'package:example/util/widget_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:riki_router/core/riki_route.dart';
import 'package:riki_router/riki_router.dart';

@RikiRoute(
  name: '/hero/demo',
  routeName: '测试hero动画',
  pageRouteType: PageRouteType.cupertino,
)
class HeroPage extends StatelessWidget {
  const HeroPage() : super();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: buildAppBar('Hero Demo'),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: GridView.builder(
          itemBuilder: (BuildContext context, int index) {
            return GestureDetector(
              onTap: () {
                RikiRouterDelegate.of(context).pushUri(
                  '/hero/demo1',
                  heroKeys: ['$index'],
                  transitionMilliseconds: 550,
                  reverseTransitionMilliseconds: 550,
                  pageRouteType: index == 0 ? null : PageRouteType.transparent,
                );
              },
              child: index == 0
                  ? _buildItem(index)
                  : Hero(
                      tag: '$index',
                      child: _buildItem(index),
                    ),
            );
          },
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            crossAxisSpacing: 10,
            childAspectRatio: 9 / 16,
            mainAxisSpacing: 10,
          ),
        ),
      ),
    );
  }

  Card _buildItem(int index) {
    return Card(
      clipBehavior: Clip.hardEdge,
      child: Column(
        children: [
          Expanded(
            child: Image.network(
              'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F031H0111515%2F20031G11515-9-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1647162193&t=ddf7ddb44ba310f4b108cebb73de9549',
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(height: 16),
          Text(
            '$index测试',
          ),
          SizedBox(height: 16),
          Text(
            '$index测试-----',
          ),
          SizedBox(height: 16),
        ],
      ),
    );
  }
}
